<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/28
 * Time: 18:11
 */

namespace app\admin\controller;
use app\admin\model\Course;

class CourseController extends BaseController
{
    public function index()
    {
        $data = Course::all();
        //var_dump($data);die;
        return view('',['data'=>$data]);
    }
    public function add()
    {
        if(request()->isAjax()){
            $data = request()->param();
            $re = Course::create($data);
            if($re){
                return ajaxMsg('1','添加成功');
            }else{
                return ajaxMsg('2','添加失败');
            }
        }
        return view();
    }
    public function edi()
    {
        if (request()->isAjax()){
            $re = Course::update(request()->param());
            if($re){
                return ajaxMsg('1','修改成功');
            }else{
                return ajaxMsg('2','修改失败未做任何修改');
            }
        }else{
            $id =   request()->param('id');
            $data = Course::get($id);
            return view('',['data'=>$data]);
        }
    }
    public function del($id)
    {
        $re = Course::destroy($id);
        if($re){
            return ajaxMsg('1','删除成功');
        }else{
            return ajaxMsg('2','删除失败');
        }
    }

}